package gatperdut.chato.lucene.parser.mechanisms;

import gatperdut.chato.lucene.parser.CMParser;
import gatperdut.chato.lucene.parseresult.mechanisms.MechanismParseResult;

import java.io.File;
import java.io.FileNotFoundException;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;

public class MechanismsParser extends CMParser {

    private final String DESCRIPTION = "description";

    public MechanismsParser( File fileToParse ) throws FileNotFoundException, XMLStreamException {
        super( fileToParse, new MechanismParseResult() );
    }

    @Override
    public void dealWithEvent( XMLEvent event ) throws XMLStreamException {
        if ( event.asStartElement().getName().getLocalPart().equals( DESCRIPTION ) ) {
            event = getEventReader().nextEvent();
            String description = event.asCharacters().getData();
            getParseResult().setDescription( description );
            getParseResult().getCatchAll().append( description + " " );
        }
    }

    @Override
    public MechanismParseResult getParseResult() {
        return (MechanismParseResult) super.getParseResult();
    }

}
